<?php $this->headScript()->appendFile($this->js('plugins/jquery.blockUI.js'))?>
<script>
$(function(){

	  $("#yearSemester, #select-class").change(function(){
		    $("#selectForm").submit();
		});
	 // 選擇階段
	 $("#stage").change(function(){
	  var id= $(this).val();
      if (id == '') {
        $("#friendlyPrint").addClass('ui-state-disabled');
       return false;
      }
      $("#friendlyPrint").removeClass('ui-state-disabled');

      if ( $("#plusCount").attr('checked') )
      var plusCount = 1;
      else
      var plusCount = 0;

      if ( $("#rateCount").attr('checked') )
      var rateCount = 1;
      else
      var rateCount = 0;
      $.blockUI({message:'<h1><?php echo $this->translate('Data reading ..')?></h1>',  border: '3px solid #f00'});
      $.post('<?php echo $this->route("get-score")?>',{
          yearSemester : $("#yearSemester").val(),
          classSn: $("#select-class").val() ,
          stage: id,
          plusCount: plusCount,
          rateCount: rateCount
       },
       function(data){
          $("#listScore").html(data);
          $.unblockUI();
      });
  });

  $("#plusCount").click(function(){
      $('#stage').trigger('change');
  });
  $("#rateCount").click(function(){
      $('#stage').trigger('change');
  });

  $("#friendlyPrint").click(function(){
      if ($(this).hasClass('ui-state-disabled'))
      return false;
      var stage = $("#stage").val();
     if ( $("#plusCount").attr('checked') )
      var plusCount = 1;
      else
      var plusCount = 0;

      if ( $("#rateCount").attr('checked') )
      var rateCount = 1;
      else
      var rateCount = 0;

      if ( $("#signPrint").attr('checked') )
      var signPrint = 1;
      else
      var signPrint = 0;

     if ( $("#rankPrint").attr('checked') )
      var rankPrint = 1;
      else
      var rankPrint = 0;

     var yearSemester = $("#yearSemester").val();
     var classSn = $("#select-class").val();
      $(this).attr('href','<?php echo $this->route("print-score")?>/stage/'+stage
      +'/yearSemester/'+yearSemester+'/classSn/'+classSn
      +'/plusCount/'+plusCount+'/rateCount/'+rateCount+'/rankPrint/'+rankPrint
      +'/signPrint/'+signPrint
      );

  });

  <?php if ($this->examineSet):?>
  $("#stage").trigger('change');
  <?php endif?>
});

</script>
<form id="selectForm" method="post" action="">
<div class="ui-widget">
<div>
<select name="yearSemester" id="yearSemester">
<?php echo $this->YearSemesterOptions($this->yearSemester,array('order'=>'year DESC'))?>
</select>
<select id="select-class" name="select-class">
<option value=""><?php echo $this->translate('choose class')?></option>
<?php echo $this->ClassNameOptions($this->yearSemester , $this->selectClass)?>
</select>
<?php if ($this->examineSet):?>
<select name="stage" id="stage">
<option value=""><?php echo $this->translate('choose stage ..')?></option>
<?php for($i=1; $i <= $this->examineSet->period; $i++):?>
<option value="<?php echo $i?>" <?php if($i==$this->stage):?>selected<?php endif?> ><?php echo sprintf($this->translate('%dth stage'),$i)?></option>
<?php endfor;?>
<option value="255" <?php if($this->stage==255):?>selected<?php endif?>><?php echo $this->translate('whole stage')?></option>
</select>

<input type="checkbox" id="plusCount"  name="plusCount" value="1" <?php  Sfs_Html::printChecked($this->plusCount)?>><label for="plusCount"><?php echo $this->translate('usually score counted')?></label>
<input type="checkbox" id="rateCount" name="rateCount"  value="1" <?php  Sfs_Html::printChecked($this->rateCount)?>><label for="rateCount"><?php echo $this->translate('rate counted')?></label>
<input type="checkbox" id="rankPrint"  name="rankPrint" value="1" <?php  Sfs_Html::printChecked($this->rankPrint)?>><label for="rankPrint"><?php echo $this->translate('print rank')?></label>
<input type="checkbox" id="signPrint"  name="signPrint" value="1" <?php  Sfs_Html::printChecked($this->signPrint)?>><label for="signPrint"><?php echo $this->translate('print sign')?></label>

<div style="float:right">
<a  id="friendlyPrint" class="fg-button ui-state-default  ui-state-disabled fg-button-icon-left ui-corner-all"  href="#"  target="_blank"><span class="ui-icon ui-icon-print"></span><?php echo $this->translate('Friendly Print')?></a>
</div>
<?php endif?>
</div>


<div id="listScore" >

</div>

</div>
</form>
<div style="clear:both"></div>